<template>
  <div>
    <el-dialog title="填写病历" :visible.sync="dialogShow" width="720px" @close="cancelInfo">
      <div class="modelInfo">
        <vue-scroll ref="vs" :ops="$store.state.ops">
          <div class="modelInfo_box">
            <span class="infoTitle">就诊概况</span>
            <span class="infoDetail">
              <span class="patientInfo">
                <span class="fontColor">就诊人：</span>
                <span class="margin8">{{MedicalRecordInfo.patientName | patientName}}</span>
                <span class="margin8">{{MedicalRecordInfo.patientSex | patientSex}}</span>
                <span class="margin8">{{MedicalRecordInfo.patientAge | patientAge}}</span>
              </span>
              <span class="patientInfo">
                <span class="fontColor">就诊时间：</span>
                <span
                  class="margin8"
                >{{MedicalRecordInfo.orderTime || MedicalRecordInfo.createTime | baseTimeFun}}</span>
              </span>
              <span class="patientInfo">
                <span class="fontColor">就诊医生：</span>
                <span class="margin8">{{MedicalRecordInfo.doctorName}}</span>
                <span class="margin8">{{MedicalRecordInfo.department}}</span>
                <span class="margin8">{{MedicalRecordInfo.doctorTitle}}</span>
              </span>
            </span>
            <el-form
              :model="MedicalRecordInfo"
              :rules="rules"
              ref="MedicalRecordInfo"
              label-width="0px"
            >
              <span class="infoTitle">患者主诉</span>
              <el-form-item prop="illnessDesc">
                <el-input
                  class="infoDetail"
                  type="textarea"
                  placeholder="请输入患者主诉"
                  :autosize="{ minRows: 1, maxRows: 3}"
                  v-model="MedicalRecordInfo.illnessDesc"
                  maxlength="300"
                  minlength="2"
                ></el-input>
              </el-form-item>
              <span class="infoTitle">初步诊断</span>
              <el-form-item prop="firstDiagnose">
                <el-input
                  class="infoDetail"
                  type="textarea"
                  :autosize="{ minRows: 1, maxRows: 3}"
                  placeholder="请输入初步诊断结论"
                  v-model="MedicalRecordInfo.firstDiagnose"
                  maxlength="100"
                  minlength="2"
                ></el-input>
              </el-form-item>
              <span class="infoTitle">处理意见</span>
              <el-form-item>
                <el-input
                  class="infoDetail"
                  type="textarea"
                  :autosize="{ minRows: 4, maxRows: 8}"
                  placeholder="请输入处理意见"
                  v-model="MedicalRecordInfo.treatmentSuggestion"
                  maxlength="200"
                  minlength="2"
                ></el-input>
              </el-form-item>
            </el-form>
          </div>
        </vue-scroll>
      </div>
      <div class="modelbottom">
        <el-button
          size="medium"
          class="base_button modelBtn_l"
          @click="submitInfo('MedicalRecordInfo')"
          round
        >保存并发送</el-button>
        <el-button
          size="medium"
          class="base_button modelBtn_r"
          @click="submitInfo('MedicalRecordInfo','recip')"
          round
        >完成病历发送并开处方</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { addMedicalHistory } from "../../requestApi/incompleteCommunication.js";
export default {
  props: ["showTrue", "patientData"],
  data() {
    return {
      dialogShow: false,
      MedicalRecordInfo: {
        firstDiagnose: "",
        treatmentSuggestion: ""
      },
      rules: {
        illnessDesc: [
          { required: true, message: "请添加患者主诉", trigger: "blur" }
        ],
        firstDiagnose: [
          { required: true, message: "请添加初步诊断", trigger: "blur" }
        ],
        treatmentSuggestion: [
          { required: true, message: "请添加处理意见", trigger: "blur" }
        ]
      }
    };
  },
  filters: {
    patientName: function(val) {
      return val ? val : "未知";
    },
    patientSex: function(val) {
      var data = "";
      if (val == 0) {
        data = "女";
      } else if (val == 1) {
        data = "男";
      } else {
        data = "未知";
      }
      return data;
    },
    patientAge: function(val) {
      return val ? val + "岁" : "未知";
    }
  },
  watch: {
    showTrue(val) {
      this.dialogShow = val;
    },
    patientData(val) {
      this.MedicalRecordInfo = { ...this.MedicalRecordInfo, ...val };
      this.clearData();
    }
  },
  created() {},
  mounted() {
    this.MedicalRecordInfo = {
      ...this.patientData,
      firstDiagnose: "",
      treatmentSuggestion: ""
    };
  },
  methods: {
    /* 保存并发送  start */
    submitInfo(formName, type) {
      let self = this;
      if (!self.MedicalRecordInfo.illnessDesc) {
        self.$message({
          type: "error",
          message: "患者主诉不能为空"
        });
      } else if (!self.MedicalRecordInfo.firstDiagnose) {
        self.$message({
          type: "error",
          message: "初步诊断不能为空"
        });
      } else {
        if (type == "recip") {
          // 跳转开处方页面
          this.$emit("submit", self.MedicalRecordInfo, "recip");
        } else {
          this.$emit("submit", self.MedicalRecordInfo, "close");
        }
      }
    },
    cancelInfo() {
      this.$emit("close");
      // this.clearData()
    },
    clearData() {
      this.MedicalRecordInfo.firstDiagnose = "";
      this.MedicalRecordInfo.treatmentSuggestion = "";
    }
  }
};
</script>

<style scoped rel="stylesheet">
.modalwrap {
  z-index: 2012;
  -webkit-overflow-scrolling: touch;
  outline: 0;
  width: 720px;
  height: 705px;
  font-size: 14px;
  font-family: MicrosoftYaHei;
  user-select: none;
  background-color: #fff;
  box-shadow: 0px 10px 20px 0px rgba(0, 0, 0, 0.1);
  border-radius: 6px;
  position: relative;
  display: flex;
  flex-direction: column;
}
.modelTitle {
  padding: 16px 24px;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  font-size: 16px;
  font-family: MicrosoftYaHei-Bold, MicrosoftYaHei;
  font-weight: bold;
  color: rgba(42, 41, 40, 1);
}

.modelInfo {
  height: 545px;
  overflow: hidden;
}
.modelInfo_box {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 0 40px;
  padding-bottom: 10px;
}
.infoTitle {
  font-size: 16px;
  font-family: PingFangSC-Medium, PingFang SC;
  font-weight: bold;
  color: rgba(42, 41, 40, 1);
  line-height: 60px;
}
.infoDetail {
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: rgba(55, 55, 55, 1);
  line-height: 20px;
}
.margin8 {
  margin: 0 8px;
}
.patientInfo {
  display: inline-block;
  width: 48%;
  line-height: 32px;
}
.fontColor {
  font-weight: 400;
  color: rgba(122, 118, 118, 1);
}
.modelbottom {
  width: 100%;
  height: 100px;
  bottom: 0;
  left: 0;
  background: rgba(241, 241, 241, 1);
  box-shadow: 0px 0px 0px 0px rgba(228, 228, 228, 1);
  border-radius: 0px 0px 6px 6px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modelBtn {
  width: 200px;
  height: 40px;
  text-align: center;
  background: rgba(255, 101, 50, 1);
  border-radius: 20px;
  color: rgba(255, 255, 255, 1);
  line-height: 40px;
}
.modelBtn_l {
  margin-right: 15px;
}
.modelBtn_r {
  margin-left: 15px;
}
@keyframes bounce-in {
  0% {
    opacity: 0;
  }

  100% {
    opacity: 1;
  }
}
</style>
